using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Diagnostics;

namespace UmlDesigner.Model
{
    [Serializable]
    class TemporaryLinkWidget : LinkWidget
    {
        internal TemporaryLinkWidget(ItemWidget src)
            : base(src, src)
        {
            // Allocate off slots for the link.
            AllocateSlotsForCircularRef();

            Debug.Assert(src != null);
        }

        internal LinkWidget CreateRealLinkWidget()
        {
            if (source.IsNote())
            {
                ItemWidget tempWidget = destination;
                destination = source;
                source = tempWidget;
            }

            Debug.Assert(LinkComplete());
            LinkWidget newLink = new LinkWidget(source, destination);

            source.AddLinkToDest(newLink);
            destination.AddLinkFromSource(newLink);

            return newLink;
        }

        internal bool LinkComplete()
        {
            return !trackingPoint && (source != destination || !source.IsLink());
        }

        private bool trackingPoint = false;
        private Point destPoint;

        internal void SetDestPoint(Point p)
        {
            destPoint = p;
            trackingPoint = true;
            instanceName = null;
        }

        internal void SetDestClass(ItemWidget dest)
        {
            Debug.Assert(dest != null);
            destination = dest;
            trackingPoint = false;
        }

        internal override void PaintItem(Graphics e)
        {
            if (LinkComplete())
            {
                if (source.IsLink() || source.IsNote())
                {
                    PaintBetweenClasses(e, source, destination, LinkWidget.LineType.NoteLink);
                }
                else
                {
                    PaintBetweenClasses(e, source, destination, LinkWidget.LineType.Association);
                }
            }
            else
            {
                PaintBetweenPoints(e, srcSlot.Position, destPoint, linkType);
            }
        }


    }
}
